<?php
defined('IN_IXDCW') or exit('Access Denied');
$do = new XdcooperModule();
$menus = array (
    array($MOD['name'].'列表', '?moduleid='.$moduleid),
);

if($_catids) require DT_ROOT.'/admin/admin_check.inc.php';

if(in_array($action, array('', 'check', 'reject', 'recycle'))) {
	$sfields = array('公司名', '会员名');
	$dfields = array('company', 'username');
	$sorder  = array('申请时间降序', '申请时间升序','信息ID降序', '信息ID升序');
	$dorder  = array('addtime DESC', 'addtime ASC', 'itemid DESC', 'itemid ASC');

	isset($fields) && isset($dfields[$fields]) or $fields = 0;
	isset($order) && isset($dorder[$order]) or $order = 0;
	$typeid = isset($typeid) ? ($typeid === '' ? -1 : intval($typeid)) : -1;

	isset($datetype) && in_array($datetype, array('edittime', 'addtime')) or $datetype = 'addtime';
	$fromdate = isset($fromdate) && preg_match("/^([0-9]{8})$/", $fromdate) ? $fromdate : '';
	$fromtime = $fromdate ? strtotime($fromdate.' 0:0:0') : 0;
	$todate = isset($todate) && preg_match("/^([0-9]{8})$/", $todate) ? $todate : '';
	$totime = $todate ? strtotime($todate.' 23:59:59') : 0;

	$link = isset($link) ? intval($link) : 0;
	$guest = isset($guest) ? intval($guest) : 0;
	$itemid or $itemid = '';
	$fields_select = dselect($sfields, 'fields', '', $fields);
	$type_select = dselect($TYPE, 'typeid', $MOD['name'].'类型', $typeid);
	$order_select  = dselect($sorder, 'order', '', $order);
	$condition = 'content!=""';
	if($_childs) $condition .= " AND catid IN (".$_childs.")";//CATE
	if($keyword) $condition .= " AND $dfields[$fields] LIKE '%$keyword%'";
	if($catid) $condition .= ($CATEGORY[$catid]['child']) ? " AND catid IN (".$CATEGORY[$catid]['arrchildid'].")" : " AND catid=$catid";
	if($fromtime) $condition .= " AND `$datetype`>=$fromtime";
	if($totime) $condition .= " AND `$datetype`<=$totime";
	if($guest) $condition .= " AND username=''";
	if($itemid) $condition = " AND itemid=$itemid";
	if($psize) $do->setPagesize($psize);

	$timetype = strpos($dorder[$order], 'edit') === false ? 'add' : '';
}
switch($action) {
	case 'show':
		if(isset($itemid)) {
			$r = $db->getOne("SELECT * FROM xd_xdcooper WHERE itemid='$itemid'");
		}
		extract($r);
		$content = json_decode($content,true);
		include tpl('xdcooper_show', $module);
		break;
	default:
		$lists = $do->getlist($condition, $dorder[$order]);
		$menuid = 1;
		include tpl('index', $module);
	break;
}
?>